<template>
  <div class="app-container ">
    <BoncTable ref="pageListRef" :hasImport="false" :hasExport="false" :hasRefresh="true" :searchForm="searchForm" :searchOptions="searchOptions"
      :columns="columns" :dataList="dataList" :total="total" :hasOperate="true" @reset="reset" @getList="getList">
      <template #status="{ row }">
        <dict-tag :options="sys_normal_disable" :value="row.status" />
      </template>
      <template #operation>
        <el-button link type="primary" icon="Edit" v-hasPermi="['system:post:edit']">修改</el-button>
        <el-button link type="primary" icon="Delete" v-hasPermi="['system:post:remove']">删除</el-button>
      </template>
    </BoncTable>
  </div>
</template>

<script setup name="Index">
import { listPost, addPost, delPost, getPost, updatePost } from '@/api/system/post'
import { toRefs } from 'vue'
const { proxy } = getCurrentInstance()
const { sys_normal_disable } = proxy.useDict('sys_normal_disable')
const searchForm = ref({ postCode: '', postName: '', status: '' })
const searchOptions = [
  { label: '岗位编码', prop: 'postCode', type: 'input', placeholder: '请输入岗位编码' },
  { label: '岗位名称', prop: 'postName', type: 'input', placeholder: '请输入岗位名称' },
  { label: '岗位状态', prop: 'status', type: 'select', options: [], placeholder: '请选择岗位状态' }
]
watch(
  () => sys_normal_disable.value,
  () => {
    searchOptions[2].options = sys_normal_disable.value
  },
  { deep: true }
)

const columns = ref([
  { prop: 'postId', label: '岗位编号' },
  { prop: 'postCode', label: '岗位编码', minWidth: 180 },
  { prop: 'postName', label: '岗位名称' },
  { prop: 'postSort', label: '岗位排序', minWidth: 120 },
  { prop: 'status', label: '状态', minWidth: 120, isSlot: true },
  { prop: 'createTime', label: '创建时间', minWidth: 120 }
])
const total = ref(0)
const dataList = ref([])
const getList = (query, body, callback) => {
  listPost({ ...query, ...body })
    .then(res => {
      callback && typeof callback === 'function' && callback()
      dataList.value = res.rows || []
      total.value = res.total || 0
    })
    .catch(err => {
      callback && typeof callback === 'function' && callback()
    })
}
const reset = () => (searchForm.value = { postCode: '', postName: '', status: '' })
</script>
<style lang="scss" scoped>
</style>
